<template>
  <div>
    <header>
      <img id="cover" :src="listInfo.coverImgUrl" />
      <div class="tilte">
        <span>歌单</span>
        <h2>{{listInfo.name}}</h2>
      </div>
      <div class="userInfo">
        <img :src="listInfo.creator.avatarUrl" />
        <span class="username">{{listInfo.creator.nickname}}</span>
        <span class="createTime">{{createTime(listInfo.createTime)}}创建</span>
      </div>
      <div class="action">
        <div class="playAll">
          <i class="iconfont icon-bofang"></i>
          <span>播放全部</span>
          <i class="iconfont icon-zengjia"></i>
        </div>
        <div class="star">
          <i class="iconfont icon-shoucang1"></i>
          <span>收藏({{listInfo.subscribedCount}})</span>
        </div>
        <div class="share">
          <i class="iconfont share icon-fenxiang1"></i>
          <span>分享({{listInfo.shareCount}})</span>
        </div>
      </div>
      <div class="listInfo">
        <ul class="tagList">
          <li>标签:</li>
          <li class="tag" v-for="(item,index) in listInfo.tags" :key="index">{{item}}/</li>
        </ul>
        <div class="songSum">
          <span>歌曲:{{listInfo.trackCount}}</span>
          <span>播放:{{listInfo.playCount}}</span>
        </div>
        <div class="describe">
          简介:{{listInfo.description}}
        </div>
      </div>
    </header>
    <div class="tab">
      <Tab :tabList="tabList"></Tab>
    </div>
    <main>
        <router-view></router-view>
    </main>
  </div>
</template>

<script>
import moment from 'moment'
import {getSheetListAllAPI,getSheetListAPI} from '@/api'
import Tab from '@/components/Tab'
export default {
    name:'SongSheet',
    data() {
        return {
            tabList:[
                {
                    path: "/songsheet/songsheetlist",
                    name: "songsheetlist",
                    label: "歌曲列表"
                },
                 {
                    path: "/songsheet/comment",
                    name: "comment",
                    label: "评论"
                },
                 {
                    path: "/songsheet/stars",
                    name: "stars",
                    label: "收藏者"
                }
            ],
            listInfo:{
              coverImgUrl:require('@/assets/images/loading.gif'),
              name:'',
              subscribedCount:0,
              shareCount:0,
              tags:[],
              playCount:0,
              description:'',
              creator:{
                nickname:'',
                avatarUrl:require('@/assets/images/loading.gif'),
              }
            },
        }
    },
    computed:{
      id(){
        return this.$route.query.id
      }
    },
    watch:{
      id(){
        this.getSheetList(this.id)
      }
    },
    components:{
        Tab
    },
    methods:{
      // 获取歌单信息
      async getSheetList(id){
        const res = await getSheetListAPI({id})
        this.listInfo = res.data.playlist
      },
      // 处理创建时间  时间戳
      createTime(time){
        let timer = moment(time);
        let m = timer.month()+1;
        let y = timer.year();
        let d = timer.date();
        m = m<10 ? '0'+m : m ;
        d = d<10 ? '0'+d : d ;
        return y + '-' + m + '-' + d;
      }
    },
    created(){
      if(this.$route.query.id!=undefined){
        this.getSheetList(this.$route.query.id)
      }
    }
};
</script>

<style lang="less" scoped>
header {
  width: 95%;
  height: 200px;
  margin: 20px auto 0px auto;
  position: relative;
  #cover {
    width: 180px;
    height: 180px;
    margin-top: 5px;
    margin-left: 5px;
    border-radius: 6px;
  }
  .tilte {
    height: 40px;
    position: absolute;
    top: 5px;
    left: 205px;
    display: flex;
    span {
      width: 32px;
      text-align: center;
      height: 20px;
      color: #ff7a9e;
      font-size: 14px;
      display: inline-block;
      padding: 0px 3px 0px 3px;
      margin-right: 10px;
      margin-top: 4px;
      border: 1px solid #ff7a9e;
      border-radius: 3px;
      display: block;
    }
    h2 {
      display: block;
      font-size: 22px;
      margin: 0;
      color: #333;
      width: 450px;
      overflow: hidden;
      word-wrap: break-word; /*强制换行*/
      overflow: hidden; /*超出隐藏*/
      text-overflow: ellipsis; /*隐藏后添加省略号*/
      white-space: nowrap; /*强制不换行*/
    }
  }
  .userInfo {
    font-size: 12px;
    position: absolute;
    top: 52px;
    left: 205px;
    display: flex;
    img {
      width: 25px;
      height: 25px;
      border-radius: 50%;
      margin-top: -4px;
      display: block;
    }
    .username {
      color: rgb(73, 135, 185);
      padding: 0 5px;
    }
    .createTime {
      color: #666;
    }
  }
  .action {
    width: 500px;
    height: 50px;
    display: flex;
    font-weight: lighter;
    font-size: 15px;
    position: absolute;
    left: 205px;
    top: 80px;
    .playAll {
      margin-right: 10px;
      height: 32px;
      background-color: #ff7a9e;
      color: white;
      line-height: 32px;
      padding: 0 15px;
      border-radius: 16px;
      cursor: pointer;
      i {
        font-size: 14px;
      }
      span {
        padding: 0 6px;
      }
      .icon-zengjia {
        padding-left: 5px;
        border-left: 1px solid rgba(255, 255, 255, 0.2);
      }
    }
    .playAll:hover {
      background-color: rgb(222, 104, 138);
    }
    .star {
      height: 32px;
      line-height: 32px;
      padding: 0 4px 0 10px;
      border: 1px solid #ccc;
      margin-right: 10px;
      border-radius: 16px;
      cursor: pointer;
      i {
        font-size: 18px;
      }
      span {
        padding: 0 6px;
      }
    }
    .star:hover {
      background-color: rgb(242, 242, 242);
    }
    .share {
      height: 32px;
      line-height: 32px;
      padding: 0 6px 0 6px;
      border: 1px solid #ccc;
      border-radius: 16px;
      cursor: pointer;
      i {
        font-size: 18px;
        border: none;
      }
    }
    .share:hover {
      background-color: rgb(242, 242, 242);
    }
  }
  .listInfo {
    font-size: 12px;
    color: #666;
    position: absolute;
    left: 205px;
    top: 125px;
    .tagList {
      display: flex;
      margin-bottom: 5px;
      li{
          padding-right: 2px;
      }
      .tag {
        color: rgb(73, 135, 185);
      }
    }
    .songSum {
      margin-bottom: 5px;
      span{
          padding-right: 5px;
      }
    }
    .describe {
      width: 550px;
      word-wrap: break-word; /*强制换行*/
      overflow: hidden; /*超出隐藏*/
      text-overflow: ellipsis; /*隐藏后添加省略号*/
      white-space: nowrap; /*强制不换行*/
    }
  }
}
</style>